package com.dream.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.dream.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@Controller
public class DemoController {
    @RequestMapping(value = "/index")
    public void getWord(HttpServletRequest request, HttpServletResponse response) {
        PrintWriter outputStream = null;
        User user=new User();
        user.setId(1);
        user.setEmail("1233@");
        user.setTelphone("11111");
        user.setUserName("王");
        user.setUserPass("123");
        String jsonString;
        jsonString = JSON.toJSONString(user, SerializerFeature.PrettyFormat);

        try {
            response.setHeader("Content-type", "text/html;charset=UTF-8");
            outputStream = response.getWriter();
            outputStream.println(jsonString);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            outputStream.close();
        }
    }
}
